<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box {
            width: 200px;
            height: 200px;
            background-color: red;
        }
    </style>
</head>

<body>
    <div id="box"></div>
    <button id="btn">点击变色</button>
    <script>
        document.getElementById("btn").onclick = clickHandler
        function clickHandler(event) {
            const colorArr = ["blue", "red", "pink", "black", "yellow", "green", "orange"]
            const ele = document.getElementById("box")
            ele.style.backgroundColor = colorArr[Math.floor(Math.random() * colorArr.length)]
        }
    </script>
</body>

</html>